package la.iok.hzsvn.lewin.movie.shopmovie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.core.shopmovie.vo.ShopMovieVo;
import la.iok.hzsvn.lewin.movie.shopmovie.model.ShopMovieListParam;
import la.iok.hzsvn.lewin.movie.shopmovie.model.ShopMovieModifyParam;
import la.iok.hzsvn.lewin.movie.shopmovie.model.ShopMovieParam;
import la.iok.hzsvn.lewin.movie.shopmovie.service.ShopMovieService;
import la.iok.hzsvn.lewin.mybatis.model.PageParam;
import la.iok.hzsvn.lewin.mybatis.model.PageVo;
import la.iok.hzsvn.lewin.mybatis.model.SortParam;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("movies")
public class MovieController {
    private final ShopMovieService shopMovieService;

    public MovieController(ShopMovieService shopMovieService) {
        this.shopMovieService = shopMovieService;
    }

    @PostMapping
    public OperatorResponse save(@RequestHeader Token token, @RequestBody ShopMovieParam param){
        shopMovieService.save(token,param);
        return OperatorResponses.success();
    }

    @PutMapping("{id}")
    public OperatorResponse modify(@RequestHeader Token token, @PathVariable Long id, @RequestBody ShopMovieModifyParam param){
        shopMovieService.modify(token,id, param);
        return OperatorResponses.success();
    }

    @GetMapping
    public SingleDataResponse<PageVo<ShopMovieVo>> page(
            SortParam sortParam, PageParam pageParam, ShopMovieListParam listParam){
        return new SingleDataResponse<>(shopMovieService.page(pageParam,sortParam,listParam));
    }

    /**
     * 剧本上线
     * @param token 操作用户
     * @param id 剧本id
     */
    @PutMapping("{id}/online")
    public OperatorResponse online(@RequestHeader Token token,@PathVariable Long id){
        shopMovieService.online(token,id);
        return OperatorResponses.success();
    }

    /**
     * 剧本下线
     * @param token 操作用户
     * @param id 剧本id
     * @return 操作结果
     */
    @PutMapping("{id}/offline")
    public OperatorResponse offline(@RequestHeader Token token,@PathVariable Long id){
        shopMovieService.offline(token,id);
        return OperatorResponses.success();
    }
}
